﻿@model RiderShop.Mobile.Modle.Purchase.ShippingCartModel


@section title
{
    购物车-满69包邮
}
@section pagetitle
{
    购物车-满69包邮
}

@section header
{
    <link rel="stylesheet" href="~/Themes/RongJi/Style/base/css/order.css">
    <style>
        .innerwrapper {
            display: none;
        }

        .del {
            float: right;
            margin: -20px 0 0;
        }

        .goods_total {
            float: right;
            padding: 0 15px 0 0;
        }

        .all {
            padding: 0 0 0 15px;
        }
    </style>
}


<div class="userCenterHeader">
    <span class="iconWrapper">
        <img src="/Themes/RongJi/Style/base/imgs/icon_long.png">
    </span>
    <h3>我的购物车</h3>
    <br class="clearfix">
</div>
<div class="content">
    <div class="address_bar">
        @if (Model.DefaultShippingAddress == null)
        {
            <div id="addrNameTxt"></div>
            <div><a class="btn btn-info" href="~/myaccount/ShippingAddress?action=cart"><i class="glyphicon glyphicon-pencil"></i> <span>请设置您的收货地址</span></a></div>
        }
        else
        {

            <strong>配送至：</strong>
            <p id="addrNameTxt">@Model.DefaultShippingAddress.ShipTo @Model.DefaultShippingAddress.CellPhone</p>
            <p id="addrNameTxt">@Model.DefaultShippingAddress.RegionAddress</p>
            <p id="addrNameTxt">@Model.DefaultShippingAddress.Address</p>
            <div><a class="btn btn-info" href="~/myaccount/ShippingAddress?action=cart"><i class="glyphicon glyphicon-pencil"></i> <span>编辑或更改</span></a></div>
        }
    </div>
    <form id="toPreCheck" method="post" action="~/Purchase/PreCheckProduct">
        @foreach (var itemInfo in Model.CartInfo.CommonProductListNoCOM)
        {

            <div class="row" id="@("cartp_"+itemInfo.ProductId)" msg_id="msg@itemInfo.ProductId">
                <div class="clearfix cardprd">
                    <div class="prdImg">
                        <a href="~/Product/ProductDetail?prd=@itemInfo.ProductId">
                            @if (itemInfo.ProductId.Trim() == "COM")
                            {
                                <img src="http://dev.rongji365.com/Storage/CommResource/COM/COM_100.jpg" alt="" />
                            }
                            else
                            {
                                <img src="@itemInfo.ImageName" alt="" />
                            }
                        </a>
                    </div>
                    <a href="~/Product/ProductDetail?prd=@itemInfo.ProductId">
                        <div class="goods_name">@itemInfo.Title</div>
                        <div class="single-price_con">单价：<span class="single-price">¥<span>@itemInfo.UnitPrice</span></span></div>
                    </a>
                    <div class="del">
                        <a pid="@itemInfo.ProductId" href="javascript:void(0)" class="btnRemove"> <span class="glyphicon glyphicon-remove f25 darkgray"></span> </a>
                    </div>
                    <br class="clearfix" />
                </div>
                <div class="single_goods_opt">
                    <div class="all">
                        <span class="cartQty">数量：</span>
                        <a class="noDirect num-operating minus btnReduce" href="javascript:void(0)" data-min="1" pid="@itemInfo.ProductId">-</a>
                        <input class="total_count s-input" type="text" name="total_count" pid="@itemInfo.ProductId" id="Qty_@itemInfo.ProductId" lqty="@itemInfo.LimitQuantity" autocomplete="off" maxlength="3" value="@itemInfo.Quantity">
                        <a class="noDirect num-operating plus btnAdd" href="javascript:void(0)" data-max="100" data-maxperuser="0" pid="@itemInfo.ProductId">+</a>
                    </div>
                    <div class="goods_total"><span class="ml10">共计：</span><span class="single_goods_total_price" id="prd_price_@itemInfo.ProductId" price="@itemInfo.UnitPrice">￥@itemInfo.SubTotal</span></div>
                    <br class="clearfix" />
                </div>
            </div>

        }
    </form>
    <div id="empty" style="display: @(Model.CartInfo.CommonProductListNoCOM.Count == 0?"block":"none")">
        <div class="mt30 mb30"></div>
        <h3>您的购物车空空如也</h3>
        <br>
        <div>
            <a href="~/Home" class="empty_go_main btn btn-default">去逛逛</a>
        </div>
    </div>
    <div id="continueShopping" style="display: @(Model.CartInfo.CommonProductListNoCOM.Count > 0?"block":"none")">
        <br>
        <div>
            <a href="~/Home" class="empty_go_main btn btn-success">继续购买更多商品</a>
        </div>
    </div>
</div>
<div class="pay_bar" name="checkgroup" attr-tag="checkMain" id="checkAllBtn">

    <span class="total">
        总计：<span class="f18"> ¥<span id="totalPrice">@Model.CartInfo.ProductPriceAmount</span></span> <em>
            （共
            <span id="totalNum">@Model.CartInfo.TotalQuantity</span> 件，不含运费）
        </em>
    </span>
    <form id="toCheckout" method="post" action="~/Purchase/CheckOut">
        <a href="javascript:void(0)" class="btn_pay" id="shopCartConfirm">去结算</a>
    </form>
</div>
<div id="loading" style="left: 188px; top: 224px; display: none;">
    <div class="bk"></div>
    <div class="cont">
        <img src="~/Themes/rongji/Style/default/images/ajax-loader.gif" alt="loading...">正在加载...
    </div>
</div>
<script>
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
        WeixinJSBridge.call('hideToolbar');
    });
    document.addEventListener('AlipayJSBridgeReady', function () {
        AlipayJSBridge.call("hideOptionMenu");
        AlipayJSBridge.call('hideToolbar');
    });
</script>

@section footer
{
    <script type="text/javascript" src="~/Utility/pages/pg_purchase.js"></script>
    <script>
        $(document).ready(function () {
            isShowPriceDetail = false;
            $(".btnReduce").click(function () {
                var pid = $(this).attr("pid");
                DeclineToCart(this, pid);
                refreshTotalAmount();
            });

            $(".btnAdd").click(function () {
                var pid = $(this).attr("pid");
                IncreaseToCart(this, pid);

                refreshTotalAmount();
            });

            $(".btnRemove").click(function () {
                var pid = $(this).attr("pid");
                KevinShop.Common.ShoppingCart.DeletePrdFromCart(pid);
                refreshTotalAmount();
            });

            $("#shopCartConfirm").click(function () {
                checkout();
            });

            $(".total_count").focusout(function () {
                var pid = $(this).attr("pid");
                UpdateProductNumber(pid);
                refreshTotalAmount();
            });

            var allowed = "0123456789";
            $(".content").delegate('.total_count', 'keypress', function (e) {
                if (229 === e.which) {
                    e.preventDefault();
                }
                var k = e.which;
                if (k === 8 || (k == 46 && e.button == -1) || k === 0) {
                    return;
                }
                var character = String.fromCharCode(k);
                if (allowed.indexOf(character) === -1) {
                    e.preventDefault();
                }
            })
            .delegate('.total_count', 'keydown', function (e) {
                if (229 === e.which) {
                    e.preventDefault();
                }
            });
            //.delegate('.total_count', 'keyup', function (e) {
            //    var count = $(this).val();
            //    if (isNaN(count)) {
            //        for (; count.length > 0 && isNaN(count) ;) {
            //            count = count.substring(0, count.length - 1);
            //        }
            //        $(this).val(count);
            //    }
            //    if (count === "" || count == 0) {
            //        count = 1;
            //        $(this).val(1);
            //    }
            //    //if (parseInt(count) <= 1) {
            //    //    $(this).closest(".row").find(".minus").css("background-color", "#d5d5d5");
            //    //} else {
            //    //    $(this).closest(".row").find(".minus").css("background-color", "#F9FAF9");
            //    //}

            //    var pid = $(this).attr("pid");
            //    var lQty = $(this).attr("lqty");
            //    if (!KevinShop.Common.ShoppingCart.CheckQuantity(count, lQty)) {

            //        return;
            //    }

            //})


        });
        function refreshTotalAmount() {
            $('#totalNum').text();

            var list = KevinShop.Common.ShoppingCart.GetProductList();
            var total = 0;
            var totalAcount = 0;
            for (var obj in list) {

                var qty = !isNaN(list[obj].Quantity) ? Number(list[obj].Quantity) : 0;
                var uprice = $("#prd_price_" + list[obj].ProductId).attr("price");
                var price = !isNaN(uprice) ? parseFloat(uprice) : 0;
                var productPrice = qty * price;

                total += qty;
                totalAcount += productPrice;
            };
            if (total > 0) {
                $('#totalNum').text(total);
                $('#totalPrice').text(totalAcount.toFixed(2));
            } else {
                $('#totalNum').text(0);
                $('#totalPrice').text(0);
                $('#empty').show();
                $('#continueShopping').hide();
                
                //$('#shopCartConfirm').disabled();
            }

            KevinShop.Common.ShoppingCart.TotalAmount = totalAcount;
            KevinShop.Common.ShoppingCart.TotalQty = total;
        }
    </script>
}